package ${package}.${moduleName}.controller;

import lombok.AllArgsConstructor;
import ${package}.${moduleName}.common.page.PageResult;
import ${package}.${moduleName}.query.${ClassName}Query;
import ${package}.${moduleName}.common.utils.Result;
import ${package}.${moduleName}.entity.${ClassName}Entity;
import ${package}.${moduleName}.service.${ClassName}Service;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
* ${tableComment}
*
* @author ${author} ${email}
* @since ${version} ${date}
*/
@RestController
@RequestMapping("gen/${functionName}")
@AllArgsConstructor
public class ${ClassName}Controller {
    private final ${ClassName}Service ${className}Service;

    @GetMapping("page")
    public Result<PageResult<${ClassName}Entity>> page(${ClassName}Query query){
        PageResult<${ClassName}Entity> page = ${className}Service.page(query);

        return Result.ok(page);
    }

    @GetMapping("list")
    public Result<List<${ClassName}Entity>> list(){
        List<${ClassName}Entity> list = ${className}Service.getList();

        return Result.ok(list);
    }

    @GetMapping("{id}")
    public Result<${ClassName}Entity> get(@PathVariable("id") Long id){
        ${ClassName}Entity entity = ${className}Service.getById(id);

        return Result.ok(entity);
    }

    @PostMapping
    public Result<String> save(@RequestBody ${ClassName}Entity entity){
        ${className}Service.save(entity);

        return Result.ok();
    }

    @PutMapping
    public Result<String> update(@RequestBody ${ClassName}Entity entity){
        ${className}Service.updateById(entity);

        return Result.ok();
    }

    @DeleteMapping
    public Result<String> delete(@RequestBody Long[] ids){
        ${className}Service.removeBatchByIds(Arrays.asList(ids));

        return Result.ok();
    }
}